#pragma once
#include "cupid.h"
#include "MsgTemplate.h"
#include "MsgProtocol.h"

namespace cupid
{
class NetMsg
{
public:
	NetMsg(void);
	virtual ~NetMsg(void);

	void	init(void);
	int		getSocketID()		{return m_idSocket;}
	int		getType	(void)		{return m_msgType;}
	int		getSize	(void)		{return m_msgSize;}

	char*	getBuf(void)		{return m_bufMsg;}

public:	
	virtual BOOL			create (char* msgBuf, DWORD dwSize);
	virtual BOOL			isValid	(void);
	virtual void			process (void *info);
	virtual bool			sendMsg (NetMsg* msg);

public:
	static int	getMaxSize	(void)		{return _MAX_MSGSIZE;}

	static NetMsg*	createMsg(int idProcess, int idSocket, int idMsg, const char* bufMsg, unsigned short msgSize);

	static NetMsg*	createMsg(int type);

	void	append(int idProcess, int idSocket);

protected:
	int		m_idProcess;
	int		m_idSocket;
	union {
		char	m_bufMsg[_MAX_MSGSIZE];
		struct {
			unsigned short	m_msgSize;
			unsigned short	m_msgType;
		};
	};

};
}